package demo.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import demo.dao.inter.UserMapper;
import demo.model.tUser;
import demo.util.MySqlSessionFactory;

@Service
public class commonService {
	
	@Autowired
	private UserMapper userMapper;

	public List<tUser> users (){
		List<tUser> list = new ArrayList<tUser>();
		tUser u1 = new tUser();
		u1.setId(1);
		u1.setName("u1");
		u1.setPassword("u1pass");
		list.add(u1);
		return list;
	}
	
	public List<tUser> testUsers (){
		return userMapper.getAllUser();
	}
	
	@Transactional
	public int testInsert (tUser user){
		if (user != null) {
			userMapper.save(user);
			return 1;
		}
		return 0;
	}
	
	@Transactional
	public int testDelete (tUser user){
		if (user != null) {
			
			return userMapper.delete(user);
		}
		return 0;
	}
}
